package question3;

public class TestInterpreteur extends junit.framework.TestCase
{
    private Memoire m;
    private Variable x1;

    public void setUp()
    {
        m  = new Memoire();
        x1 = new Variable( m, "x1", 5 );
    }

    public void test_UneConstante()
    {
        Expression expr = new Constante( 3 );
        assertEquals( 3, expr.interprete(m) );	
    }

    public void test_DeVariables()
    {
        Memoire m1 = new Memoire();
        Expression expr = new Variable( m1, "i" );
        assertEquals( 0, expr.interprete(m1) );
        expr = new Variable( m1, "j", 55 );
        assertEquals( 55, expr.interprete(m1) );
    }

    public void test_UneAddition1()
    {
        Expression expr = new Addition( new Constante(3), new Constante(2) );
        assertEquals( 5, expr.interprete(m) );	
    }

    public void testFactoriel()
    {
        assertEquals( 5, m.lire("x1") );
        assertEquals( 120, new Factoriel(x1).interprete(m) );
    }

}
